feat: add pool_exists(asset) -> bool public view entrypoint - #246
Merged
Conversation
Closes AnchorNet-Org#106 - Add pool_exists(env, asset) -> bool to AnchornetContract in src/lib.rs, delegating directly to storage::has_pool which already existed internally. Placed immediately after pool() in the pool-view section. - Fix pre-existing compile error: client alias list_settlements_by_anchor_and_asset referenced a non-existent method name list_settlements_by_anchor_asset; corrected to list_settlements_by_anch_asset (the actual exported symbol). - Add 6 regression tests in src/test.rs: test_pool_exists_false_before_any_liquidity test_pool_exists_true_after_provide_liquidity test_pool_exists_true_after_provide_liquidity_multi test_pool_exists_true_after_full_withdrawal test_pool_exists_is_per_asset test_pool_exists_consistent_with_pool_getter - Update README.md contract interface table with the new read-only entrypoint. pool() error-returning behavior and Error::PoolNotFound are unchanged. No authorization required (pure read view, no state mutation).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #106
Exposes a
pool_exists(env, asset) -> boolentrypoint onAnchornetContractso off-chain integrators can check whether any liquidity has ever been provided for an asset without having to catchError::PoolNotFoundfrompool().Changes
src/lib.rspool_exists(env, asset) -> boolimmediately afterpool()in the pool-view section. Delegates directly to the already-existingstorage::has_pool— no new storage helper needed.list_settlements_by_anchor_and_assetclient alias referenced the non-existent methodlist_settlements_by_anchor_assetinstead of the actual exported symbollist_settlements_by_anch_asset.src/test.rsAdded 6 test cases covering all acceptance criteria:
test_pool_exists_false_before_any_liquidityfalsefor an asset that has never had liquidity providedtest_pool_exists_true_after_provide_liquiditytrueafterprovide_liquiditytest_pool_exists_true_after_provide_liquidity_multitrueafterprovide_liquidity_multitest_pool_exists_true_after_full_withdrawaltrueeven after the pool is drained to zero (pool entry persists, matchinglist_assetsbehaviour)test_pool_exists_is_per_assettest_pool_exists_consistent_with_pool_getterpool_exists == false ↔ pool() == PoolNotFound,pool_exists == true ↔ pool() succeedsREADME.mdpool_exists(asset)row to the contract interface table betweenpoolandtotal_liquidity.Acceptance criteria
pool_exists(asset)returnsfalsefor an asset that has never had liquidity providedpool_exists(asset)returnstrueonceprovide_liquidity/provide_liquidity_multihas touched that assetpool()behavior andError::PoolNotFoundare unchangedSecurity
Pure read view — no state mutation, no authorization requirement. Off-chain integrators can check pool existence without speculative calls that would otherwise revert.